#include <Decoder.h>

#define LED A0

Decoder dec;//12, 11, 10, 8, 13, 9); // DEC_CD, DEC_WR, DEC_RD, DEC_XFLG1, DEC_XFLG2, DEC_FCLK
unsigned long count;
unsigned long countDebug;
char strCount[50];
long randnum;

void setup()
{ 
  // Initialize Serial IO
  Serial.begin(9600);
  randomSeed(analogRead(0));
  
  pinMode(LED, OUTPUT);
  digitalWrite(LED, HIGH);
  
  dec.startClock();
  delay(5000);
  dec.initializeDecoder(); 
}

void loop()
{
  if(Serial.available()){
    char buffer[10];
    Serial.readBytesUntil('\n',buffer, 10); 
    
    if(buffer[0] == 'r'){
      Serial.println("reset");
      dec.initializeDecoder();
    }

    if(buffer[0] == 'd')
    {
      Serial.println("disable");
      dec.disableAB(); 
    }
    
    if(buffer[0] == 'e')
    {
      Serial.println("enable");
      dec.enableAB(); 
    }


    if(buffer[0] == 's')
    {
      randnum = random(300);
      Serial.print("set");
      Serial.print(randnum);
      dec.setCounter(randnum);
    }

  }

  countDebug = dec.readCountDEBUG();
  sprintf(strCount, "DebugCount: %l\n", countDebug);
  Serial.println(strCount);

  count = dec.readCounter();
  sprintf(strCount, "Count: %lu\n", count);
  Serial.println(strCount);
  
  delay(2000);

}




